home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / pppfsm.h < prev    next >
C/C++ Source or Header  |  1994-09-16  |  7KB  |  233 lines

  1. /****************************************************************************
  2. *    $Id: pppfsm.h 1.2 92/08/10 20:17:26 ROOT_DOS Exp Locker: ROOT_DOS $
  3. *    pppfsm.h                                                                *
  4. *    PPP state machine definitions and structures.                            *
  5. *                                                                            *
  6. *    10 Aug 92    1.2        GT    Add ppp_s.idle_timer.                            *
  7. ****************************************************************************/
  8.  
  9. #ifndef _PPPFSM_H
  10. #define _PPPFSM_H
  11.  
  12. #ifndef    _MBUF_H
  13. #include "mbuf.h"
  14. #endif
  15.  
  16. #ifndef    _PROC_H
  17. #include "proc.h"
  18. #endif
  19.  
  20. #ifndef    _IFACE_H
  21. #include "iface.h"
  22. #endif
  23.  
  24. #ifndef    _TIMER_H
  25. #include "timer.h"
  26. #endif
  27.  
  28.                 /* 00: serious internal problems */
  29.                 /* 01: interoperability problems */
  30.                 /* 02: state machine messages */
  31. #define PPP_DEBUG_RAW
  32. #define PPP_DEBUG_OPTIONS    0x08
  33. #define PPP_DEBUG_CHECKS(x)    if(PPPtrace & 0x40) trace_log(PPPiface,x);
  34. #define PPP_DEBUG_ROUTINES(x)    if(PPPtrace & 0x80) trace_log(PPPiface,x);
  35.  
  36. /* config packet header */
  37. struct config_hdr {
  38.     byte_t code;
  39. #define CONFIG_REQ     1
  40. #define CONFIG_ACK     2
  41. #define CONFIG_NAK     3
  42. #define CONFIG_REJ     4
  43. #define TERM_REQ     5
  44. #define TERM_ACK     6
  45. #define CODE_REJ     7
  46. #define PROT_REJ     8
  47. #define ECHO_REQ     9
  48. #define ECHO_REPLY    10
  49. #define DISCARD_REQ    11
  50. #define QUALITY_REPORT    12
  51.  
  52.     byte_t id;
  53.     int16 len;
  54. };
  55. #define CONFIG_HDR_LEN    4    /* Length of config packet header */
  56.  
  57.  
  58. /* config option header */
  59. struct option_hdr {
  60.     byte_t type;        /* protocol dependant types */
  61.     byte_t len;
  62. };
  63. #define OPTION_HDR_LEN    2    /* Length of option header */
  64.  
  65.  
  66. /* Supported Configuration Protocol index */
  67. enum {
  68.     Lcp,
  69.     Pap,
  70.     IPcp,
  71.     fsmi_Size
  72. };
  73.  
  74. struct fsm_s;        /* forward declaration */
  75.  
  76. /* Protocol Constants needed by State Machine */
  77. struct fsm_constant_s {
  78.     char *name;            /* Name of protocol */
  79.     int16 protocol;            /* Protocol number */
  80.     int16 recognize;        /* Config codes to use (bits) */
  81.  
  82.     byte_t fsmi;            /* Finite State Machine index */
  83.     byte_t try_req;            /* # tries for request */
  84.     byte_t try_nak;            /* # tries for nak substitutes */
  85.     byte_t try_terminate;        /* # tries for terminate */
  86.     int32 timeout;            /* Time for timeouts (milliseconds)*/
  87.  
  88.     /* To free structure */
  89.     void (*free)        __ARGS((struct fsm_s *fsm_p));
  90.  
  91.     /* Set negotiation to initial values */
  92.     void (*reset)        __ARGS((struct fsm_s *fsm_p));
  93.     /* When leaving Closed or Listen */
  94.     void (*starting)    __ARGS((struct fsm_s *fsm_p));
  95.     /* When entering Opened */
  96.     void (*opening)        __ARGS((struct fsm_s *fsm_p));
  97.     /* When leaving Opened */
  98.     void (*closing)        __ARGS((struct fsm_s *fsm_p));
  99.     /* When entering Closed or Listen (after termination) */
  100.     void (*stopping)    __ARGS((struct fsm_s *fsm_p));
  101.  
  102.     struct mbuf *(*makereq)    __ARGS((struct fsm_s *fsm_p));
  103.  
  104.     int (*request)        __ARGS((struct fsm_s *fsm_p,
  105.                     struct config_hdr *hdr,
  106.                     struct mbuf *bp));
  107.     int (*ack)        __ARGS((struct fsm_s *fsm_p,
  108.                     struct config_hdr *hdr,
  109.                     struct mbuf *bp));
  110.     int (*nak)        __ARGS((struct fsm_s *fsm_p,
  111.                     struct config_hdr *hdr,
  112.                     struct mbuf *bp));
  113.     int (*reject)        __ARGS((struct fsm_s *fsm_p,
  114.                     struct config_hdr *hdr,
  115.                     struct mbuf *bp));
  116. };
  117.  
  118. /* FSM states */
  119. enum {
  120.     fsmCLOSED,
  121.     fsmLISTEN,
  122.     fsmREQ_Sent,
  123.     fsmACK_Rcvd,
  124.     fsmACK_Sent,
  125.     fsmOPENED,
  126.     fsmTERM_Sent,
  127.     fsmState_Size
  128. };
  129.  
  130. /* State Machine Control Block */
  131. struct fsm_s {
  132.     byte_t state;            /* FSM state */
  133.     byte_t lastid;            /* ID of last REQ we sent */
  134.  
  135.     byte_t flags;
  136. #define PPP_ESCAPED    0x01
  137. #define PPP_TOSS    0x02
  138. #define FSM_PASSIVE    0x40    /* opened passive */
  139. #define FSM_ACTIVE    0x80    /* opened active */
  140.  
  141.     byte_t retry;            /* counter for timeouts */
  142.     byte_t try_req;            /* # tries for request */
  143.     byte_t try_terminate;        /* # tries for terminate */
  144.  
  145.     byte_t retry_nak;        /* counter for naks of requests */
  146.     byte_t try_nak;            /* # tries for nak substitutes */
  147.  
  148.     struct ppp_s *ppp_p;        /* the ppp we belong to */
  149.     struct timer timer;
  150.     struct fsm_constant_s *pdc;    /* protocol dependent constants */
  151.     void *pdv;            /* protocol dependent variables */
  152. };
  153.  
  154.  
  155. /* Link Phases */
  156. enum {
  157.     pppDEAD,        /* Waiting for physical layer */
  158.     pppLCP,            /* Link Control Phase */
  159.     pppAP,            /* Authentication Phase */
  160.     pppREADY,        /* Link ready for traffic */
  161.     pppTERMINATE,        /* Termination Phase */
  162.     pppPhase_Size
  163. };
  164.  
  165. /* PPP control block */
  166. struct ppp_s {
  167.     struct iface *iface;        /* pointer to interface block */
  168.  
  169.     byte_t phase;            /* phase of link initialization */
  170.     byte_t id;            /* id counter for connection */
  171.  
  172.     byte_t flags;
  173. #define PPP_AP_LOCAL    0x10    /* local authentication */
  174. #define PPP_AP_REMOTE    0x20    /* remote authentication */
  175.  
  176.     byte_t trace;            /* trace flags for connection */
  177.  
  178.     struct fsm_s fsm[fsmi_Size];    /* finite state machines */
  179.  
  180.     int32 upsince;            /* Timestamp when Link Opened */
  181.     char *peername;            /* Peername from remote (if any) */
  182.  
  183.     int32 OutTxOctetCount;        /* # octets sent */
  184.     int32 OutOpenFlag;        /* # of open flags sent */
  185.     int16 OutNCP[fsmi_Size];    /* # NCP packets sent by protocol */
  186.     int16 OutError;            /* # packets with error on send */
  187.     int16 OutMemory;        /* # alloc failures on send */
  188.  
  189.     int32 InRxOctetCount;        /* # octets received */
  190.     int32 InOpenFlag;        /* # of open flags */
  191.     int16 InNCP[fsmi_Size];        /* # NCP packets by protocol */
  192.     int16 InUnknown;        /* # unknown packets received */
  193.     int16 InChecksum;        /* # packets with bad checksum */
  194.     int16 InFrame;            /* # packets with frame error */
  195.     int16 InError;            /* # packets with other error */
  196.     int16 InMemory;         /* # alloc failures */
  197.  
  198.     int32 idle_durn;                    /* idle timeout duration (ms)        */
  199.     struct timer idle_timer;            /* idle timer data                    */
  200. };
  201. #define NULLPPP    (struct ppp_s *)0
  202.  
  203.  
  204. extern char *fsmStates[];
  205. extern char *fsmCodes[];
  206.  
  207. struct mbuf *htoncnf __ARGS((struct config_hdr *cnf, struct mbuf *data));
  208. int ntohcnf __ARGS((struct config_hdr *cnf, struct mbuf **bpp));
  209. int ntohopt __ARGS((struct option_hdr *opt, struct mbuf **bpp));
  210.  
  211. void fsm_no_action    __ARGS((struct fsm_s *fsm_p));
  212. int fsm_no_check    __ARGS((struct fsm_s *fsm_p,
  213.                 struct config_hdr *hdr,
  214.                 struct mbuf *bp));
  215.  
  216. void fsm_log    __ARGS((struct fsm_s *fsm_p, char *comment));
  217. void fsm_timer    __ARGS((struct fsm_s *fsm_p));
  218.  
  219. int fsm_send    __ARGS((struct fsm_s *fsm_p, byte_t code,
  220.             byte_t id, struct mbuf *data));
  221. int fsm_sendreq    __ARGS((struct fsm_s *fsm_p));
  222.  
  223. void fsm_proc    __ARGS((struct fsm_s *fsm_p, struct mbuf *bp));
  224.  
  225. void fsm_start    __ARGS((struct fsm_s *fsm_p));
  226. void fsm_down    __ARGS((struct fsm_s *fsm_p));
  227. void fsm_close    __ARGS((struct fsm_s *fsm_p));
  228.  
  229. void fsm_init    __ARGS((struct fsm_s *fsm_p));
  230. void fsm_free    __ARGS((struct fsm_s *fsm_p));
  231.  
  232. #endif /* _PPPFSM_H */
  233.